-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement judgedaemon fixme's #2745
base: main
Are you sure you want to change the base?
Conversation
136028a
to
b455297
Compare
b455297
to
9e00e09
Compare
cec1019
to
d6f20c2
Compare
3c22760
to
8cf34b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just reviewing commit 936fc63 - I think it would be good to split this PR into multiple smaller ones that are independent.
4cf0179
to
348ea2d
Compare
judge/judgedaemon.main.php
Outdated
echo "Error: parsing options failed.\nPlease check: `register_argc_arg` in php.ini.\n"; | ||
usage(); | ||
} | ||
$unknown = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be clearer:
$unknown = false; | |
$unknown_option = false; |
judge/judgedaemon.main.php
Outdated
if (str_starts_with($arg, '-') && !array_key_exists(ltrim($arg, '-'), $options)) { | ||
echo "Error: Unknown option: $arg\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work if you pass multiple options like -df
.
The documentation on this is not very clear. You can encounter the `False` by using unset($argv) which would be a misconfiguration so the error message is now also improved. A better explanation can be found here: https://bugs.php.net/bug.php?id=81352 Which has those comments; ``` [2021-08-12 15:19 UTC] [email protected] Prior to PHP 8.0.0, FALSE was returned if the function was called with unexpected parameters or parameter types. Most other functions returned NULL in that case. Anyhow, there is no need to document that, since this is actually undefined behavior[1]. For all relevant PHP versions, FALSE will also be returned, if neither $_SERVER nor $argv exists or are not arrays. [1] <https://www.php.net/manual/en/functions.internal.php> [2022-11-26 06:42 UTC] schamberumarcelo at gmail dot com getopt() will return an empty array if there is no error in splitting strings to args variable. GetOptions() will return a true value if the command line could be processed successfully. Otherwise, it will write error messages using die() and warn(). (https://www.imyccpay.com)github.com ``` given that we run PHP>8.0 and the explanation that parsing will stop for the first non-option I think we'll never encounter the false in practice. To be save we now check the shortoptions string for the right format. To be sure an internal function is now added which does some extra parsing to find unknown arguments, alternative would be to use: (https://www.php.net/manual/en/function.getopt.php#83414).
578eda8
to
00f5ab4
Compare
foreach($long_options as $long_option) { | ||
$stripped_arg = substr($arg, 2); | ||
if (str_starts_with($long_option, $stripped_arg) && $stripped_arg !== $long_option) { | ||
echo "Error: Shorten long options is not supported: $arg\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "Error: Shorten long options is not supported: $arg\n"; | |
echo "Error: shortening long options is not supported: $arg\n"; |
if (str_starts_with($long_option, $stripped_arg) && $stripped_arg !== $long_option) { | ||
echo "Error: Shorten long options is not supported: $arg\n"; | ||
$unknown_option = true; | ||
} elseif (!array_key_exists($stripped_arg, $options)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this will work with something like --my-long-option=foo
.
Based on feedback by @meisterT most of the
error(
calls are now changed todisable(
calls to display this in the webinterface.I'll do some squashing after getting approval.
Part of this is also put in #2809 so it's better to discuss/merge that one first and afterwards discuss the parsing of the CLI options.